package leetcode;

import com.alibaba.fastjson.JSON;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;

/**
 * @Description：
 * @Author：LiDong
 * @Create：2021/3/10
 * @Version：1.0.0
 */
public class Test1 {

    private static final Logger logger = LoggerFactory.getLogger(Test1.class);


    @Test
    public void test1(){
        int[] arr = {1,2,4,5,7};
        int[] ints = twoSum(arr, 6);
        logger.info(JSON.toJSONString(ints));
    }


    public int[] twoSum(int[] nums, int target) {
        Set<Integer> list = new HashSet<>();
        for(int i=0;i<nums.length-1;i++){
            for(int j=i+1;j<nums.length;j++){
                if(nums[i]+nums[j]==target){
                    list.add(i);
                    list.add(j);
                }
            }
        }
        int[] arr = new int[list.size()];
        for (int i = 0; i < list.toArray().length; i++) {
            arr[i] = (int) list.toArray()[i];
        }
        return arr;

    }
}
